const app = getApp()



Page({
  data: {
    latitude: 34.53005,
    longitude: 109.108347,
    cover_image_number:0,
    content:[],
    things_title:'西安工商学院',
    play_val:true,
    audio_src:'https://www.ruoai.cn/static/xgs/2.mp3',
    markers:[],
    polygons:[{
        points:[{
            latitude:34.526852,
            longitude:109.11045
        },{
            latitude:34.533284,
            longitude:109.112273
        },{
            latitude:34.534574,
            longitude:109.106558
        },{
            latitude:34.531174,
            longitude:109.105447
        },{
            latitude:34.53162,
            longitude:109.103569
        },{
            latitude:34.52936,
            longitude:109.102642
        },
        {
            latitude:34.528184,
            longitude:109.10868
        },
        {
            latitude:34.526852,
            longitude:109.11045
        }],
        fillColor: "transparent",//这里面设置透明度 后面加数字代表透明度
        strokeColor: "#ccc",
        strokeWidth: 5,
        zIndex: 1
    }]
  },
  panel: function (e) {

     if (e.currentTarget.dataset.index != this.data.showIndex) {

       this.setData({

         showIndex: e.currentTarget.dataset.index

       })

     } else {

       this.setData({

        showIndex: 0

       })

     }

   },
  onLoad: function () {
    this.init();
  },
  onShow:function(){
    this.markers();
  },
  bindmarkertap:function(e){
    console.log(e.detail.markerId);
    wx.navigateTo({
        url: '/pages/detail/detail?ditu_id='+e.detail.markerId,
    })
  },
  init(){
      let that = this;
      wx.request({
        url: 'https://www.ruoai.cn/xgs/',
        method:'GET',
        success:(data)=>{
            if (data.data.status == 200) {
                that.setData({content:data.data.data});
            }
            this.markers();
        },fail:(err)=>{
            console.log('error');
        }
      })
  },
  markers(){

      let arr = this.data.content;
      let res = [];
      for(let i=0; i<arr.length; i++){
        res.push({
            iconPath: 'https://pan.yatui.com/d/public/xgs/navigator/markers/'+arr[i].things_id+'.jpg',
            longitude:arr[i]['longtitude'],
            latitude:arr[i]['latitude'],
            id: arr[i].things_id,
            width: 35,
            height: 35
        });

    }
    this.setData({markers:res});
},


})
